package com.tarena.dang.actions.order;

import java.util.List;

import com.tarena.dang.actions.BaseAction;
import com.tarena.dang.pojos.CartItem;
import com.tarena.dang.pojos.User;
import com.tarena.dang.services.CartFactory;
import com.tarena.dang.services.CartService;
import com.tarena.dang.utils.Constant;

public class NewOrderAction extends BaseAction {
	private List<CartItem> buyList;
	private double totalPrice;
	private int userId;

	public String execute() {
		User user = (User) session.get(Constant.USER);
		if (user != null) {
			CartService cart = CartFactory.getCart(session);
			buyList = cart.getBuyList();
			totalPrice = cart.count();
			userId = user.getId();
			return "success";
		} else {
			return "login";
		}
	}

	public double getTotalPrice() {
		return totalPrice;
	}

	public void setTotalPrice(double totalPrice) {
		this.totalPrice = totalPrice;
	}

	public List<CartItem> getBuyList() {
		return buyList;
	}

	public void setBuyList(List<CartItem> buyList) {
		this.buyList = buyList;
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}
}
